package org.ithang.application.teamBonus;

import org.ithang.tools.model.Action;
import org.ithang.tools.model.ActionResult;
import org.ithang.tools.model.ActionValues;
import org.ithang.tools.model.Pager;
import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ithang.application.staticBonus.bean.StaticBonus;
import org.ithang.application.teamBonus.bean.TeamBonus;
import org.ithang.application.teamBonus.service.TeamBonusService;

/**
 * 加速分红
 * @author zyt 控制器
 *
 */
@Controller
@RequestMapping("/app/teamBonus")
public class TeamBonusAction extends Action<TeamBonus>{

    @Autowired
    private TeamBonusService teamBonusService; 


    @ResponseBody
	@RequestMapping(value="add",method=RequestMethod.POST)
	public ActionResult add(TeamBonus teamBonus){
		teamBonusService.add(teamBonus);
		return success();
	}
	
	 @RequestMapping("form")
    public String form(@RequestParam(value="id",required=false)Long id,Model m){
    	if(null!=id){
    		TeamBonus bean=teamBonusService.get(id);
    		m.addAttribute(bean);
    	}else{
    		m.addAttribute(new TeamBonus());
    	}
    	return "app/teamBonus/form";
    }
	
	
	@ResponseBody
	@RequestMapping(value="update",method=RequestMethod.POST)
	public ActionResult update(TeamBonus teamBonus){
		teamBonusService.update(teamBonus);
		return success();
	}


    @ResponseBody
	@RequestMapping(value="get",method=RequestMethod.GET)
	public ActionResult get(Long id){
		TeamBonus r=teamBonusService.get(id);
		return success(r);
	}
	
	@ResponseBody
	@RequestMapping(value="delete",method=RequestMethod.POST)
	public ActionResult delete(@RequestParam(value="id",required=false)Long id,@RequestParam(value="ids",required=false)String ids){
		
		if(null!=id&&id>0){
			teamBonusService.delete(id);	
		}
		
		if(null!=ids&&ids.length()>0){
			teamBonusService.batchDelete(ids.split(","));
		}
		
		return success();
	}
	
	@ResponseBody
	@RequestMapping(value="list",method={RequestMethod.GET,RequestMethod.POST})
	public ActionResult list(Long... ids){
		return success(teamBonusService.list(ids));
	}
	
	@ResponseBody
	@RequestMapping(value="page",method=RequestMethod.POST)
	public ActionResult page(TeamBonus teamBonus,Pager<TeamBonus> page){
	    page.setBean(teamBonus);
	    List<TeamBonus> data=teamBonusService.page(page);
	    
	    page.setPage(false);
	    Double tmount=teamBonusService.getTamount(page);
	    if(null!=data&&!data.isEmpty()){
	    	for(TeamBonus d:data){
	    		d.setTamount(tmount==null?0:tmount);
	    	}
	    }
	    
	    page.setData(data);
		return success(page);
	}
	
	@ResponseBody
	@RequestMapping(value="query",method=RequestMethod.POST)
	public ActionResult query(HttpServletRequest request){
		ActionValues values=new ActionValues(request);
		return success(teamBonusService.query(values));
	}
     

}